package com.solr.sboot.solr.config;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;

import javax.annotation.Resource;
import java.net.MalformedURLException;

/**
 * @描述: solr配置文件
 * @类名:
 * @作者: yangshuang
 * @创建时间: 2017/8/19 17:19
 * @版本: v1.0
 */
@Configuration
@EnableSolrRepositories(basePackages = "com.solr.sboot.solr.repository",multicoreSupport = true)
@PropertySource(value = "classpath:/solr.properties")
public class SolrConfiguration {
    private static final String SOLR_HOST = "solr.host";

    @Resource
    private Environment environment;

    @Bean
    public SolrClient solrClient() throws MalformedURLException {
        String solrHost = environment.getRequiredProperty(SOLR_HOST);
        return new LBHttpSolrClient(solrHost);
    }

}
